package com.gitee.srurl.system.controller;

import com.gitee.srurl.core.annotation.Login;
import com.gitee.srurl.core.util.login.LoginHelper;
import com.gitee.srurl.system.biz.LoginBiz;
import com.gitee.srurl.system.params.LoginParams;
import com.gitee.srurl.system.util.response.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zxw
 * @date 2023/5/3 14:16
 */
@RestController
@RequestMapping("auth/login")
@RequiredArgsConstructor
public class LoginController {

    private final LoginBiz loginBiz;

    @PostMapping
    public R<Map<String, Object>> userLogin(@RequestBody LoginParams loginParams) {

        Map<String, Object> token = loginBiz.login(loginParams, false);
        return R.ok(token);
    }

    @PostMapping("api")
    public R<Map<String, Object>> apiUserLogin(@RequestBody LoginParams loginParams) {

        Map<String, Object> token = loginBiz.login(loginParams, true);
        return R.ok(token);
    }

    @Login(apiAccess = Login.ApiAccess.BOTH)
    @PostMapping("logout")
    public R<Void> logout() {

        loginBiz.logout();
        return R.ok();
    }
}
